// 提供网络计算的服务
#pragma
#include <iostream>
#include "pro.hpp"
enum
{
    Div_Zero = 1,
    other_Oper
};

class ServerCal
{
public:
    Response calHelper(Request &req)
    {
        Response resp(1, 0);
        switch (req.op)
        {
            case '+':
                resp.result = req.x + req.y;
                break;
            case '-':
                resp.result = req.x - req.y;
                break;
            case '/':
            {
                if (req.y == 0)
                    resp.code = Div_Zero;
                else    resp.result = req.x / req.y;
                break;
            }
            case '*':
                resp.result = req.x * req.y;
                break;
            case '%':
            {
                if (req.y == 0)
                    resp.code = other_Oper;
                else    resp.result = req.x % req.y;
                break;
            }
        }
    }

    std::string Calculator(std::string package)
    {
        std::string content;
        bool r=Decode(package,&content);
        if(!r)
            return "";
        Request req;
        r=req.Deserialize(content);
        if(!r)
            return "";

        content="";
        Response resp=calHelper(req);

        resp.Serialize(&content);
        content=Encode(content);
        
    }
    // len"\n"10+ 20"\n"
};
